import { useState, useEffect } from 'react';
import {listPictureTagCategoryUsingGet} from "@/services/backend/pictureController";
 // 确保正确导入 API

const usePictureTagCategory = () => {
  const [tagList, setTagList] = useState<string[]>([]);
  const [categoryList, setCategoryList] = useState<string[]>([]);
  const [loading, setLoading] = useState<boolean>(false);
  const [error, setError] = useState<string | null>(null);

  useEffect(() => {
    const loadPictureTagCategory = async () => {
      setLoading(true);
      setError(null);
      try {
        const res = await  listPictureTagCategoryUsingGet();
        setTagList(res.data?.tagList || []);

        setCategoryList([ "全部" , ...res.data?.categoryList || [] ]);

      } catch (err) {
        setError('Failed to load data.');
      } finally {
        setLoading(false);
      }
    };

    loadPictureTagCategory();
  }, []); // 空数组意味着仅在组件挂载时加载一次

  return {tagList,categoryList, loading, error };
};

export default usePictureTagCategory;
